<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>购物车</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />

    <style type="text/css">
        .text-white {
            color: #ffffff !important;
        }

        .aui-grid [class*=aui-col-] {
            padding: 0.75rem 0;
        }

        .aui-bar-tab .aui-active {
            color: #E94B41
        }

        .goods-head {
            height: 2.2rem
        }

        .shop-logo {
            height: .9rem;
            width: .9rem;
            margin-right: .3rem
        }

        .del-img {
            height: .7rem;
            width: .65rem
        }

        .goods-item {
            margin: .6rem;
            padding: 0 .6rem
        }

        .goods-img {
            height: 4.3rem;
            width: 4.3rem;
            margin-right: .6rem
        }

        .num-chang img {
            height: 1rem;
            width: 1rem
        }

        .goods-info {
            height: 5.5rem
        }

        .goods-text {
            width: calc(100% - 4.9rem)
        }

        .to-order-confirm {
            height: 2.8rem;
            justify-content: flex-end;
        }

        .to-order-confirm-btn {
            border-radius: 1rem;
            margin-left: .6rem;
            border: none
        }
        /*.goods-item:last-child{
          margin-bottom: 3.1rem
        }*/
        /*head*/
    </style>
</head>

<body>
    <!-- 顶部 -->
    <div id="app">
        <section style="margin-bottom:3.1rem">
            <div class="goods-item white-bg-radius" v-for='(item,index) in cartItems' @click='getIndex(index)'>
                <div class="goods-head flex-justify-between">
                    <div class="shop-info flex-align-center">
                        <img class='shop-logo' src="../image/index/logo1.png" alt="">
                        <div class="font-14 text-color-3">
                            {{item.shopName}}
                        </div>
                    </div>
                    <img class='del-img' src="../image/cart/lajitong.png" alt="">
                </div>
                <div class="goods-info flex-align-center" v-for='(item,index) in item.goods'>
                    <img class='goods-img' src="../image/index/logo1.png" alt="">
                    <div class="goods-text">
                        <div class="goods-title text-color-3 font-13 font-semibold ellipsis line-clamp-two">
                            {{item.goodsName}}
                        </div>
                        <div class="text-color-9 font-10">
                            {{item.specify}}
                        </div>
                        <div class="text-color-9 font-10">
                            预计{{item.time}}可提货
                        </div>
                        <div class="flex-justify-between" style="margin-top:4px">
                            <div class="red-text font-12">
                                ￥<span class="font-17">{{item.price}}</span>
                            </div>
                            <div class="num-chang flex-center-between">
                                <img src="../image/index/jian.png" tapmode @click='goodsReduce(index,item.num)'>
                                <span class="font-13" style="padding:0 .6rem">{{item.num}}</span>
                                <img src="../image/index/jia.png" tapmode @click='goodsAdd(index,item.num)'>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="to-order-confirm flex-align-center">
                    <div class="font-14 text-color-0">
                        合计<span class="font-17 red-text">¥{{item.total}}</span>
                    </div>
                    <button class='to-order-confirm-btn red-btn font-14' name="button" tapmode @click='toOrderConfirm'>去结算</button>
                </div>
            </div>
        </section>

        <footer class="aui-bar aui-bar-tab">
            <div class="aui-bar-tab-item" @click='toHome'>
                <img class='bottom-seeting-img' src="../image/main/main_home_unchecked.png" alt="">
                <div class="aui-bar-tab-label font-9 text-color-6">首页</div>
            </div>
            <div class="aui-bar-tab-item aui-active">
                <img class='bottom-seeting-img' src="../image/main/main_cart_checked.png" alt="">
                <div class="aui-bar-tab-label font-9 ">购物车</div>
            </div>
            <div class="aui-bar-tab-item" @click='toPerson'>
                <img class='bottom-seeting-img' src="../image/main/main_person_unchecked.png" alt="">
                <div class="aui-bar-tab-label font-9 text-color-6">我的</div>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript " src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js "></script>


<script type="text/javascript ">
    apiready = function() {
        var vm = new Vue({
            el: '#app',
            data: {
                cartItems: [{
                    shopId: 1,
                    shopName: '万嘉便利店1',
                    total: 0,
                    goods: [{
                        goodsName: '商品商品商品商品商品商品商品商品商品商品商品商品商品商品1',
                        specify: '去冰/五分甜',
                        time: '07/18',
                        price: 18.0,
                        num: 2,
                        id: 11
                    }, {
                        goodsName: '商品商品商品商品商品商品商品商品商品商品商品商品商品商品2',
                        specify: '去冰/五分甜',
                        time: '07/19',
                        price: 20.0,
                        num: 3,
                        id: 12
                    }]
                }, {
                    shopId: 2,
                    shopName: '万嘉便利店2',
                    total: 0,
                    goods: [{
                        goodsName: '商品商品商品商品商品商品商品商品商品商品商品商品商品商品3',
                        specify: '去冰/五分甜',
                        time: '07/20',
                        price: 20.0,
                        num: 4,
                        goodsId: 13
                    }, {
                        goodsName: '商品商品商品商品商品商品商品商品商品商品商品商品商品商品4',
                        specify: '去冰/五分甜',
                        time: '07/21',
                        price: 10.0,
                        num: 5,
                        goodsId: 14
                    }]
                }],
                shopIndex: 0
            },
            //初始化加载   显示总价总数量
            created: function() {
                let items = this.cartItems;
                for (var i = 0; i < items.length; i++) {
                   this.shopIndex = i
                }
                // alert(this.shopIndex)
                let shopIdx = this.shopIndex;
                let goodsArr = this.cartItems[shopIdx].goods;
                let total = 0;
                for (let i = 0; i < goodsArr.length; i++) {
                    total += goodsArr[i].num * goodsArr[i].price
                }
                this.cartItems[shopIdx].goods = goodsArr;
                this.cartItems[shopIdx].total = total.toFixed(2);
            },

            methods: {
                toPerson: function() {
                  api.openFrame({
                      name: 'main-person_win',
                      url: './main-person_win.html',
                      rect: {
                          x: 0,
                          y: 0,
                          w: $api.winWidth,
                          h: $api.winHeight
                      },
                      pageParam: {
                          name: 'test'
                      },
                      bounces: true,
                      bgColor: 'rgba(0,0,0,0)',
                      vScrollBarEnabled: true,
                      hScrollBarEnabled: true
                  });
                },
                toHome: function() {
                  api.openFrame({
                      name: 'index_win',
                      url: './index_win.html',
                      rect: {
                          x: 0,
                          y: 0,
                          w: $api.winWidth,
                          h: $api.winHeight
                      },
                      pageParam: {
                          name: 'test'
                      },
                      bounces: true,
                      bgColor: 'rgba(0,0,0,0)',
                      vScrollBarEnabled: true,
                      hScrollBarEnabled: true
                  })
                },
                getIndex: function(index) {
                    this.shopIndex = index
                },
                goodsAdd: function(index, num) {
                    let shopIdx = this.shopIndex;
                    let goodsNum = num;
                    goodsNum = goodsNum + 1;
                    this.cartItems[shopIdx].goods[index].num = goodsNum;
                    this.countPrice()
                },
                goodsReduce: function(index, num) {
                    let shopIdx = this.shopIndex;
                    let goodsNum = num;
                    if (goodsNum <= 1) {
                        alert('不能在减少了')
                        return
                    }
                    goodsNum = goodsNum - 1;
                    this.cartItems[shopIdx].goods[index].num = goodsNum;
                    this.countPrice()
                },
                countPrice: function() {
                    let shopIdx = this.shopIndex;
                    let goodsArr = this.cartItems[shopIdx].goods;
                    let total = 0;
                    for (let i = 0; i < goodsArr.length; i++) {
                        total += goodsArr[i].num * goodsArr[i].price
                    }
                    this.cartItems[shopIdx].goods = goodsArr;
                    this.cartItems[shopIdx].total = total.toFixed(2);
                },
                // leftDel: function() {
                //     var listViewEntity = api.require('listViewEntity');
                //     listViewEntity.open({
                //         rect: {
                //             x: 0,
                //             y: 0,
                //             w: api.winWidth,
                //             h: api.frameHeight
                //         },
                //         data: [{
                //             title: '标题标题标题标题标题',
                //             subTitle: '子标题',
                //             itemHeight: 55,
                //             rightBtns: []
                //         }, {
                //             title: '标题标题标题标题标题',
                //             subTitle: '子标题',
                //             itemHeight: 55,
                //             rightBtns: []
                //         }, {
                //             title: '标题标题标题标题标题',
                //             subTitle: '子标题',
                //             itemHeight: 55,
                //             rightBtns: []
                //         }],
                //         rightBtns: [{
                //             bgColor: '#388e8e',
                //             activeBgColor: '',
                //             width: 70,
                //             title: '删除',
                //             titleSize: 12,
                //             titleColor: '#fff',
                //             icon: '',
                //             iconWidth: 20
                //         }],
                //         styles: {
                //             borderColor: '#696969',
                //             item: {
                //                 bgColor: '#AFEEEE',
                //                 activeBgColor: '#F5F5F5',
                //                 titleSize: 12.0,
                //                 titleColor: '#000',
                //                 subTitleSize: 12.0,
                //                 subTitleColor: '#000'
                //             }
                //         },
                //         fixedOn: api.frameName
                //     }, function(ret, err) {
                //         if (ret) {
                //             alert(JSON.stringify(ret));
                //         } else {
                //             alert(JSON.stringify(err));
                //         }
                //     });
                // },
                toOrderConfirm:function(){
                  api.openWin({
                      name: 'order-confirm',
                      url: './order-confirm.html',
                      pageParam: {
                          shopId: 'shopId'
                      }
                  });

                }

            },
        });



    }
</script>

</html>
